package top.yeyusmile.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yeyusmile.common.MyTemplate;
import top.yeyusmile.common.TypeConstant;
import top.yeyusmile.pojo.MyQQMessage;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author 夜雨
 * @Web www.yeyusmile.top
 * @date 2022/3/16 11:47
 */
@Service
public class SendMsgServiceImpl implements SendMsgService {

    @Autowired
    private final MyTemplate myTemplate;

    public SendMsgServiceImpl(MyTemplate myTemplate) {
        this.myTemplate = myTemplate;
    }

    @Override
    public void sendMsg(String str, MyQQMessage message) {

        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqType());
        params.put("c3", message.getMqFromid());
        params.put("c4", message.getMqFromqq());
        params.put("c5", str);
        myTemplate.sendMsg(params);
    }

    @Override
    public void handleGroupInvite(int handleType, MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqMsgdata());
        params.put("c3", handleType);
        params.put("c4", "");
        params.put("c5", "");
        myTemplate.handleGroupEvent(params);
    }

    @Override
    public void handleFriendEvent(int handleType, MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqFromqq());
        params.put("c3", handleType);
        params.put("c4", "");
        myTemplate.handleFriendEvent(params);
    }

    @Override
    public Map<String, Object> uploadPic(String url, MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqType());
        if (message.getMqType() == TypeConstant.MSGTYPE_FRIEDN) {
            params.put("c3", message.getMqFromqq());
        } else if (message.getMqType() == TypeConstant.MSGTYPE_GROUP) {
            params.put("c3", message.getMqFromid());
        } else {
            params.put("c3", "");
        }
        params.put("c4", url);
        return myTemplate.upLoadPic(params);
    }

    @Override
    public void shutUp(MyQQMessage message, String qq, Integer second) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqFromid());
        params.put("c3", qq);
        params.put("c4", second);
        myTemplate.shutUp(params);
    }

    @Override
    public void withDrawMsg(MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", message.getMqFromid());
        params.put("c3", message.getMqMsgseq());
        params.put("c4", message.getMqMsgid());
        myTemplate.withDrawMsg(params);
    }

    @Override
    public void sendMsg2Frind(String str, MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", TypeConstant.MSGTYPE_FRIEDN);
        params.put("c3", message.getMqFromid());
        params.put("c4", message.getMqFromqq());
        params.put("c5", str);
        myTemplate.sendMsg(params);
    }

    @Override
    public void sendMsg2Group(String str, MyQQMessage message) {
        Map<String, Object> params = new LinkedHashMap<>();
        params.put("c1", message.getMqRobot());
        params.put("c2", TypeConstant.MSGTYPE_GROUP);
        params.put("c3", message.getMqFromid());
        params.put("c4", message.getMqFromqq());
        params.put("c5", str);
        myTemplate.sendMsg(params);
    }


}
